package com.example.basic.service.impl;

import com.example.basic.dao.LogMapper;
import com.example.basic.domain.Log;
import com.example.basic.domain.User;
import com.example.basic.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mjw
 * @date 2023/6/7
 */
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public PageInfo<Log> selectLog(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Log> logList = logMapper.selectLog();
        PageInfo<Log> pageInfo = new PageInfo<>(logList);
        return pageInfo;
    }

    @Override
    public List<Log> selectAll() {
        int pageNum = 1;
        int pageSize = 50;
        List<Log> resultList = new ArrayList<>();
        List<Log> logList = selectPage(resultList, pageNum, pageSize);
        System.out.println("所有的数据的数量为--->" + logList.size());
        return logList;
    }

    public List<Log> selectPage(List<Log> resultList, int pageNum, int pageSize) {
        //调用分页接口，一次查询全部
        PageInfo<Log> pageInfo = selectLog(pageNum, pageSize);
        long endRow = pageInfo.getEndRow();
        long total = pageInfo.getTotal();
        System.out.println("当前的pageNum为--->" + pageNum + "endRow为--->" + endRow + "total为--->" + total);
        resultList.addAll(pageInfo.getList());
        System.out.println(pageInfo.getList());
        if (endRow < total) {
            selectPage(resultList, pageNum + 1, pageSize);
        }
        return resultList;
    }
}
